<?php 
include_once 'inc/config.inc.php';
include_once 'inc/mysql.inc.php';
include_once 'inc/tool.inc.php';
$link=connect();
$member_id=is_login($link);
if(!isset($_GET['id']) || !is_numeric($_GET['id'])){
	skip('index.php', 'error', '父版块id参数不合法!');
}
// 查询sfk_father_module发板块信息
$query="select * from sfk_father_module where id={$_GET['id']} LIMIT 1";
$result_father=execute($link, $query);
if(mysqli_num_rows($result_father)==0){
	skip('index.php', 'error', '父版块不存在!');
}
$data_father=$result_father->fetch_assoc();

// 查询父板块下所有的子版块以及今日内发布的帖子
$query = "SELECT a.id as content_id,b.id,b.module_name from sfk_content a LEFT JOIN sfk_son_module b ON a.module_id = b.id WHERE b.father_module_id = {$_GET['id']}";
$count_all = execute($link,$query);
$query1 = $query." AND time > CURDATE()";
$count_today = execute($link,$query1);

$template['title']='父版块列表页';
$template['css']=array('style/public.css','style/list.css');
?>
<?php include 'inc/header.inc.php'?>
<div id="position" class="auto">
	 <a href="index.php">首页</a> &gt; <?php echo $data_father['module_name']?>
</div>
<div id="main" class="auto">
	<div id="left">
		<div class="box_wrap">
			<h3><?php echo $data_father['module_name']?></h3>
			<div class="num">
			    今日：<span><?php echo $count_today->num_rows?></span>&nbsp;&nbsp;&nbsp;
			    总帖：<span><?php echo $count_all->num_rows?></span>
			    <div class="moderator"> 子版块：  <?php
                    while ($name = $count_all->fetch_assoc()) {
                        echo "<a href='list_son.php?id={$name["id"]}'>{$name['module_name']} </a>";
                    }
                    ?>
                </div>
			</div>
		</div>
		<div style="clear:both;"></div>
		<ul class="postsList">
			<?php
            $query = "SELECT a.id, a.title, a.time, a.new_time, b.id as son_id, b.module_name, b.father_module_id, c.name
                from sfk_content a 
                LEFT JOIN sfk_son_module b ON a.module_id = b.id 
                left JOIN sfk_member c ON a.member_id = c.id
                WHERE b.father_module_id = '{$_GET['id']}' order by a.time  desc";
            $result_content=execute($link,$query);
			while ($data_content=$result_content->fetch_assoc()) {
			?>
			<li>
				<div class="smallPic">
					<a href="#">
						<img width="45" height="45"src="style/2374101_small.jpg">
					</a>
				</div>
				<div class="subject">
					<div class="titleWrap"><a href="list_son.php?id=<?=$data_content['son_id']?>">[<?=$data_content['module_name']?>]</a>&nbsp;&nbsp;<h2><a href="show.php?id=<?=$data_content['id']?>"><?=$data_content['title']?></a></h2></div>
					<p>
						楼主：<?=$data_content['name']?>&nbsp;<?=$data_content['time']?>&nbsp;&nbsp;&nbsp;&nbsp;最后回复：<?=$data_content['new_time']?>
					</p>
				</div>
				<div class="count">
					<p>
						回复<br /><span>41</span>
					</p>
					<p>
						浏览<br /><span>896</span>
					</p>
				</div>
				<div style="clear:both;"></div>
			</li>
            <?php } ?>
		</ul>
		<div class="pages_wrap">
			<a class="btn publish" target="_blank"  href="publish.php?id=<?=$_GET['id']?>"></a>
			<div class="pages">
				<a>« 上一页</a>
				<a>1</a>
				<span>2</span>
				<a>3</a>
				<a>4</a>
				<a>...13</a>
				<a>下一页 »</a>
			</div>
			<div style="clear:both;"></div>
		</div>
	</div>
    <div id="right">
        <div class="classList">
            <div class="title">版块列表</div>
            <ul class="listWrap">
                <?php
                $query="select * from sfk_father_module";
                $result_father=execute($link, $query);
                while($data_father=mysqli_fetch_assoc($result_father)){
                    ?>
                    <li>
                        <h2><a href="list_father.php?id=<?php echo $data_father['id']?>"><?php echo $data_father['module_name']?></a></h2>
                        <ul>
                            <?php
                            $query="select * from sfk_son_module where father_module_id={$data_father['id']}";
                            $result_son=execute($link, $query);
                            while($data_son=mysqli_fetch_assoc($result_son)){
                                ?>
                                <li><h3><a href="list_son.php?id=<?php echo $data_son['id']?>"><?php echo $data_son['module_name']?></a></h3></li>
                                <?php
                            }
                            ?>
                        </ul>
                    </li>
                    <?php
                }
                ?>
            </ul>
        </div>
    </div>
	<div style="clear:both;"></div>
</div>
<?php include 'inc/footer.inc.php'?>